// map.js
class CulturalMap {
    constructor() {
        this.map = L.map('map-container').setView([24.9072, 118.584], 13);
        this.initBasemap();
        this.loadCulturalSites();
        this.initFilters();
    }

    initBasemap() {
        L.tileLayer('https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png', {
            attribution: '© OpenStreetMap contributors'
        }).addTo(this.map);
    }

    loadCulturalSites() {
        fetch('json/map.json')
            .then(response => response.json())
            .then(data => this.renderMarkers(data));
    }

    renderMarkers(sites) {
        sites.forEach(site => {
            const marker = L.marker([site.lat, site.lng])
                .addTo(this.map)
                .bindPopup(`<h3>${site.name}</h3><p>${site.type}</p>`);

            marker.on('click', () => this.showDetailPanel(site.id));
        });
    }

    showDetailPanel(siteId) {
        console.log(`显示编号为 ${siteId} 的详情`);
        // 后续可在此处添加弹窗或跳转逻辑
    }

    initFilters() {
        // 实现筛选功能（后续再开发）
    }
}
